package com.sun.wanandroid.ui.splash.task

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import com.google.auto.service.AutoService
import com.sun.module_base.theme.white
import com.sun.module_network.utils.logd
import com.sun.wanandroid.ui.splash.ISplashComposableTask
import com.sun.wanandroid.ui.splash.SplashViewModel
import com.sun.wanandroid.utils.SignCheck

/**
 *@author:sunc
 *@time :2025/7/25 10:39
 *@desc: 描述 签名校验
 */
@AutoService(ISplashComposableTask::class)
class AppSignatureComposableTask : ISplashComposableTask {
    override val content: @Composable ((SplashViewModel) -> Unit)
        get() = { AppSignatureScreen(viewModel = it) }

    override val index: Int
        get() = 0
}


@Composable
fun AppSignatureScreen(viewModel: SplashViewModel) {
    val context = LocalContext.current
    val signCheck: SignCheck = SignCheck(context, "49:EA:75:81:35:37:23:40:07:A5:5B:6A:05:DF:BB:5B:BE:FD:5E:7B")

    "AppSignatureScreen${signCheck.check()}  ".logd()
    if (signCheck.check()) {
        viewModel.FindNextTask()
    } else {
        var openDialog by remember { mutableStateOf(true) }
        if (openDialog) {
            AlertDialog(
                modifier = Modifier.fillMaxWidth(fraction = 0.9f),
                onDismissRequest = {
                    openDialog = false
                    viewModel.exitApp()
                }, title = { Text("警告") }, text = {
                    Text(text = "您当前使用的应用非官方版本，请前往官方渠道下载正版。")
                }, confirmButton = {
                    Button(
                        onClick = {
                            openDialog = false
                            viewModel.exitApp()
                        }) {
                        Text("退出去应用商店下载", color = white)
                    }
                })
        }
    }
}

class AppSignatureScreen {
}